package output

import (
	"gitee.com/krio/ginc/example/core/exerr"
	"github.com/gin-gonic/gin"
)

const OutputAdmin = "admin"

// AdminFormatter 后台格式
type AdminFormatter struct{}

func (f *AdminFormatter) Format(ctx *gin.Context, resp exerr.IExerr) {
	code := int32(resp.GetHTTPStatus())
	if resp.GetCode() == exerr.OK.GetCode() {
		code = 0
	}
	ctx.JSON(200, AdminResponse{
		Code:   code,
		Msg:    resp.GetMessage(),
		SubMsg: resp.GetSubmsg(),
		Data:   resp.GetData(),
	})
}

type AdminResponse struct {
	Code   int32       `json:"code"`
	Msg    string      `json:"msg"`
	SubMsg string      `json:"submsg"`
	Data   interface{} `json:"data"`
}
